<template>
  <div>
    <a-button style='margin-right: 8px;' type='primary' icon='save' @click='openModal'>{{ title }}</a-button>
    <div class='components-input-demo-presuffix' v-if='avalid'>
      <j-modal
        :visible.sync='visible'
        :width='1200'
        :title='title'
      >
        <template>
          <div class='table-page-search-wrapper'>
            <a-form layout='inline'>
              <a-row :gutter='24'>
                <a-col :span='6'>
                  <a-form-model-item label='调换日(起)' prop='jDate'>
                    <j-date v-model='queryParam.newDate' :showTime='true' dateFormat='YYYY-MM-DD' />
                  </a-form-model-item>
                </a-col>
                <a-col :span='6'>
                  <a-form-model-item label='调换日(止)' prop='jDate'>
                    <j-date v-model='queryParam.oldDate' :showTime='true' dateFormat='YYYY-MM-DD' />
                  </a-form-model-item>
                </a-col>
                <a-col :span='6'>
                  <a-form-model-item label='年级' prop='queryParam.gradeId'>
                    <j-dict-select-tag v-model='queryParam.gradeId' @change='changeGradeId' placeholder='请选择年级'
                                       dictCode='cou_grade,grade_name,id,tenant_id  is not null order by  grade_order' />
                  </a-form-model-item>
                </a-col>

                <a-col :span='6'>
                  <a-form-model-item label='班级' prop='queryParam.classId'>
                    <j-dict-select-tag placeholder='请选择班级' v-model='queryParam.classId'
                                       :dictCode='queryParamSelect.classIdSelect' />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col>
                   <span style='text-align: center;overflow: hidden;' class='table-page-search-submitButtons'>
                     <j-checkbox v-model='queryParam.schoolId' @change='changeValue'
                                 :options='jCheckboxOptions'></j-checkbox>
                     <a-button type='primary' @click='exectChangeCourse' icon='save'>确定调换</a-button>
                   </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
        </template>
        <template slot='footer'>
          <a-button @click='closeMessage'>关闭</a-button>
        </template>
      </j-modal>

    </div>
  </div>
</template>

<script>

import { getAction, postAction } from '@api/manage'

export default {
  name: 'JSelectOnl',
  components: {},
  props: {
    title: {
      type: String,
      default: '',
      required: false
    }
  },
  data() {
    return {
      showText: '',
      title: '',
      avalid: false,
      visible: false,
      queryParam: {},
      queryParamSelect: {
        classIdSelect: 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 order by  class_order'
      },
      newDate: '',
      oldDate: '',
      jCheckboxOptions: [
        { label: '全校', value: '-1' }
      ]
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
  },
  methods: {
    openModal() {
      if (this.visible === false) {
        this.visible = true
      }
      if (this.avalid === false) {
        this.avalid = true
      }
    },
    //更改年级-->选择考试，选择班级
    changeGradeId() {
      if (this.queryParam.gradeId) { //判断不为空
        this.queryParamSelect.classIdSelect = 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code=\'' + this.queryParam.gradeId + '\' order by  class_order'
      }
    },
    exectChangeCourse() {
      if (!this.queryParam.newDate || !this.queryParam.oldDate) {
        this.$message.success('请选择需要调换的时间！')
        return
      }
      if (!this.queryParam.gradeId && !this.queryParam.classId && !this.queryParam.schoolId) {
        this.$message.success('请选择需要调换的对象！')
        return
      }
      let params = {
        oneWeekData: {
          teachingJobExeDate: this.queryParam.newDate,
          gradeId: this.queryParam.gradeId,
          classId: this.queryParam.classId,
          schoolId: this.queryParam.schoolId
        },
        tooWeekData: {
          teachingJobExeDate: this.queryParam.oldDate,
          gradeId: this.queryParam.gradeId,
          classId: this.queryParam.classId,
          schoolId: this.queryParam.schoolId
        }
      }
      postAction('/couteachingjobexecute/couTeachingJobExecute/changeCoures', params).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.closeMessage();
        } else {
          this.$message.error(res.message)
        }
      })
    },
    closeMessage() {
      if (this.visible === true) {
        this.visible = false
      }
      if (this.avalid === true) {
        this.avalid = false
      }
      this.$emit("closeJselectOnl",{});
    },
    changeValue() {
      this.queryParam.gradeId = null
      this.queryParam.classId = null
    }
  }
}
</script>
<style scoped>
.components-input-demo-presuffix .anticon-close-circle {
  cursor: pointer;
  color: #ccc;
  transition: color 0.3s;
  font-size: 12px;
}

.components-input-demo-presuffix .anticon-close-circle:hover {
  color: #f5222d;
}

.components-input-demo-presuffix .anticon-close-circle:active {
  color: #666;
}
</style>